import plotly.graph_objects as go
import numpy as np

# 生成数据
x, y, z = np.random.uniform(-5, 5, size=(3, 100))

# 创建三维散点图
fig = go.Figure(data=[go.Scatter3d(
    x=x,
    y=y,
    z=z,
    mode='markers',
    marker=dict(
        size=5,
        color=z,                # 根据z值设置颜色
        colorscale='Viridis',   # 选择颜色方案
        opacity=0.8
    )
)])

# 设置布局
fig.update_layout(
    title='3D 散点图示例',
    scene=dict(
        xaxis_title='X 轴',
        yaxis_title='Y 轴',
        zaxis_title='Z 轴'
    )
)

# 显示图形
fig.show()